package com.itboye.ihomebank.adapter.key;

import java.util.List;
import java.util.Map;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.custom.RoundImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
 * 开锁记录的适配器
 *
 */
public class ItemUnlockingAdapter extends BaseAdapter {
	private Context context;
	private List<Map<String, Object>> list;
	
	public ItemUnlockingAdapter(Context context,List<Map<String, Object>> list) {
		this.context=context;
		this.list=list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder holder;
		
		if(view==null){
			view=LayoutInflater.from(context).inflate(R.layout.item_unlocking_record, null);
			holder=new ViewHolder();
			holder.unlock_roundview=(RoundImageView) view.findViewById(R.id.unlock_roundview);
			holder.unlock_name=(TextView) view.findViewById(R.id.unlock_name);
			holder.unlock_state=(TextView) view.findViewById(R.id.unlock_state);
			holder.unlock_time=(TextView) view.findViewById(R.id.unlock_time);
			
			view.setTag(holder);
		}else{
			holder=(ViewHolder) view.getTag();
		}
		
		//List<Map<String,Object>>的时候用这个
		holder.unlock_roundview.setBackgroundResource(Integer.valueOf(list.get(position).get("img").toString()));
		holder.unlock_name.setText(list.get(position).get("name").toString());
		holder.unlock_state.setText(list.get(position).get("state").toString());
		holder.unlock_time.setText(list.get(position).get("time").toString());
			
		
		return view;
	}
	
	class ViewHolder{
		RoundImageView unlock_roundview;
		TextView unlock_name;
		TextView unlock_state;
		TextView unlock_time;
	}


}
